package com.stageadminserver.adminserver.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.stagecommon.common.pojo.DemandFormat;
import com.stagecommon.common.pojo.RespBean;
import com.stageadminserver.adminserver.service.DemandFormatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: yxl
 * @since: 2022-04-24
 **/
@RestController
@RequestMapping("/demandFormat")
public class DemandFormatController {

    @Autowired
    private DemandFormatService demandFormatService;

    /**
     * 分页获取需求格式
     * @param currentPage
     * @param size
     * @param demandFormat
     * @return
     */
    @PostMapping("/searchFormatByPage")
    public RespBean<IPage> searchFormatByPage(@RequestParam(defaultValue = "1") Integer currentPage,
                                              @RequestParam(defaultValue = "10") Integer size,
                                              @RequestBody DemandFormat demandFormat){
        return demandFormatService.getFormatByPage(currentPage,size,demandFormat);
    }

    /**
     * 根据需求格式id获取需求格式
     * @param demandFormat
     * @return
     */
    @PostMapping("/searchFormatById")
    public RespBean<DemandFormat> searchFormatById(@RequestBody DemandFormat demandFormat){
        return demandFormatService.getFormatById(demandFormat.getDemandFormatId());
    }

    /**
     * 根据需求格式id获取需求格式
     * @param demandFormat
     * @return
     */
    @PostMapping("/changeFormatById")
    public RespBean<Integer> changeFormatById(@RequestBody DemandFormat demandFormat){
        return demandFormatService.updateFormatById(demandFormat);
    }

    /**
     * 添加需求格式
     * @param demandFormat
     * @return
     */
    @PostMapping("/addFormat")
    public RespBean<Integer> addFormat(@RequestBody DemandFormat demandFormat){
        return demandFormatService.addFormat(demandFormat);
    }

    /**
     * 根据需求格式id删除需求格式
     * @param demandFormat
     * @return
     */
    @PostMapping("/deleteFormatById")
    public RespBean<Integer> deleteFormatById(@RequestBody DemandFormat demandFormat){
        return demandFormatService.deleteFormatById(demandFormat);
    }
}
